#include<iostream>
#include<fstream>
#include<boost/mpi.hpp>
#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
using namespace boost::mpi;
#include"sm_system.h"
#include"serialization.h"
#include"sm_solver.h"

using std::cout;
using std::cin;
using std::endl;

using namespace SM;

int main()
{
  timer clock;
  environment env;
  communicator world;
  System_Tz_SM effV;
  System_Tz_SM_M effVm;
  
  if(world.rank()==0)
    {
      //effV.setup("test.sp","test.int");
      string spfile,vfile;
      cin>>spfile>>vfile;
      effV.setup(spfile.c_str(),vfile.c_str());
      //effV.setup("usdbpn.sp","usdbpn.int");      
      effVm.setup(&effV);
    }
  broadcast(world,effVm,0);

  int vN,vZ,restriction,MM,Par,num;
  if(world.rank()==0)
    {
      cin>>vN>>vZ>>restriction>>MM>>Par>>num;
    }
  broadcast(world,vN,0);
  broadcast(world,vZ,0);
  broadcast(world,restriction,0);
  broadcast(world,MM,0);
  broadcast(world,Par,0);
  broadcast(world,num,0);
  
  SMSolver smsolver(world,&effVm,vN,vZ);//,vN,vZ
  smsolver.setupConfigs(MM,Par,restriction);//MM,Par,restriction
  // smsolver.diag();
  smsolver.diag_lanczos(num);//num,savevecs,step=1
  smsolver.printStates(num);
  //  smsolver.calOccuNums(0);
  //  smsolver.printOccuNums();
  if(world.rank()==0)
    cout<<"total time: "<<clock.elapsed()/60.<<" min"<<endl;
  return 0;
}
